//-----------------Sonic CD Fire Gun Script-------------------//
// Yeah...

// Aliases
#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.Timer1
#alias Object.Value2	:	Object.Timer2
#alias Object.Value3	:	Object.YVelocity
#alias Object.Value4	:	Object.XVelocity

// Collision Sides
#alias 0	:	CSIDE_FLOOR
#alias 1	:	CSIDE_LWALL
#alias 2	:	CSIDE_RWALL
// States
#alias 0	:	FIRE_FLY
#alias 1	:	FIRE_FALLEN

sub ObjectMain
	switch Object.PropertyValue
		case 0
			ObjectTileCollision(CSIDE_FLOOR, 0, 16, 0)
			if CheckResult == true
				Object.State = FIRE_FALLEN
			end if
			if Object.State == FIRE_FLY
				Object.YVelocity = 0x25000
				Object.YPos += Object.YVelocity
			else
				Object.Timer++
			end if
			if Object.Timer == 12
				ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, Object.XPos, Object.YPos)
			end if
			break
		case 1
			Object.Direction = FACING_LEFT
			ObjectTileCollision(CSIDE_LWALL, -32, 0, 0)
			if CheckResult == true
				Object.State = FIRE_FALLEN
			end if
			if Object.State == FIRE_FLY
				Object.XVelocity = -0x25000
				Object.XPos += Object.XVelocity
			else
				Object.Timer++
			end if
			if Object.Timer == 12
				ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, Object.XPos, Object.YPos)
			end if
			break
		case 2
			Object.Direction = FACING_RIGHT
			ObjectTileCollision(CSIDE_RWALL, 32, 0, 0)
			if CheckResult == true
				Object.State = FIRE_FALLEN
			end if
			if Object.State == FIRE_FLY
				Object.XVelocity = 0x25000
				Object.XPos += Object.XVelocity
			else
				Object.Timer++
			end if
			if Object.Timer == 12
				ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, Object.XPos, Object.YPos)
			end if
			break
	end switch
end sub

sub ObjectPlayerInteraction
	switch Object.PropertyValue
		case 0
		PlayerObjectCollision(C_TOUCH, -8, -8, 8, 16)
		if CheckResult == true
			CallFunction(Player_Hit)
		end if
		break
		case 1
		case 2
		PlayerObjectCollision(C_TOUCH, -8, -8, 16, 8)
		if CheckResult == true
			CallFunction(Player_Hit)
		end if
		break
	end switch
end sub

sub ObjectDraw
	switch Object.PropertyValue
		case 0
			if Object.State == FIRE_FLY
				Object.Timer1++
				if Object.Timer1 == 3
					Object.Timer1 = 0
					Object.Frame++
					if Object.Frame > 1
						Object.Frame = 0
					end if 
				end if
			else
				if Object.Timer == 6
					Object.Frame = 1
				end if
				if Object.Timer >= 6
					Object.Timer2++
					if Object.Timer2 == 3
						Object.Timer2 = 0
						Object.Frame++
					end if
				end if
			end if
			DrawSprite(Object.Frame)
			break
		case 1
		case 2
			if Object.Frame < 4
				Object.Frame = 4
			end if 
			if Object.State == FIRE_FLY
				Object.Timer1++
				if Object.Timer1 == 3
					Object.Timer1 = 0
					Object.Frame++
					if Object.Frame > 5
						Object.Frame = 4
					end if 
				end if
			else
				if Object.Timer == 6
					Object.Frame = 5
				end if
				if Object.Timer >= 6
					Object.Timer2++
					if Object.Timer2 == 3
						Object.Timer2 = 0
						Object.Frame++
					end if
				end if
			end if
			if Object.PropertyValue == 2
				DrawSprite(Object.Frame)
			else
				DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.YPos)
			end if
			break
		end switch
end sub

sub ObjectStartup
	LoadSpriteSheet("R2/Objects2.gif")

	SpriteFrame(-8, -17, 16, 33, 182, 134)
	SpriteFrame(-8, -17, 16, 33, 199, 134)
	SpriteFrame(-8, -17, 16, 33, 216, 134)
	SpriteFrame(-8, -17, 16, 33, 233, 134)
	
	SpriteFrame(-17, -8, 33, 16, 166, 169)
	SpriteFrame(-17, -8, 33, 16, 200, 169)
	SpriteFrame(-17, -8, 33, 16, 166, 186)
	SpriteFrame(-17, -8, 33, 16, 200, 186)
end sub